import 'package:flutter/material.dart';
import 'package:flutterapp/logic/all_logic.dart';

class GlobalModel extends ChangeNotifier {
  GlobalLogic logic;
  BuildContext context;

  ///app的名字
  String appName = "Travel";

  ///是否开启主页背景渐变
  bool isBgGradient = false;

  ///是否开启主页背景颜色跟随卡片图标颜色
  bool isBgChangeWithCard = false;

  ///是否开启卡片图标颜色跟随主页背景
  bool isCardChangeWithBg = false;

  ///是否开启首页动画
  bool enableSplashAnimation = true;

  ///是否开启主页卡片无限循环滚动
  bool enableInfiniteScroll = false;

  ///是否开启天气
  bool enableWeatherShow = false;

  ///是否开启主页背景为网络图片
  bool enableNetPicBgInMainPage = false;

  ///是否开启自动夜间模式
  bool enableAutoDarkMode = false;

  ///当前自动夜间模式，白天的时间区间,比如：'7/20'
  String autoDarkModeTimeRange = '';

  ///当前主页网络背景图片地址
  String currentMainPageBgUrl = '';

  ///当前位置信息(经纬度)
  String currentPosition = '';

  ///当前语言
  List<String> currentLanguageCode = ['zh', 'CN'];
  String currentLanguage = '中文';
  Locale currentLocale;

  ///导航栏头部选择网络图片时的图片地址
  String currentNetPicUrl = "";

  ///是否进入登录页
  bool goToLogin = false;

  GlobalModel() {
    logic = GlobalLogic(this);
  }

  void setContext(BuildContext context) {
    if (this.context == null) {
      this.context = context;
    }
    Future.wait([
      logic.getAppName(),
      logic.getLoginState(),
    ]).then((value) {
      currentLocale = Locale(currentLanguageCode[0], currentLanguageCode[1]);
      refresh();
    });
  }

  @override
  void dispose() {
    super.dispose();
    debugPrint("GlobalModel销毁了");
  }

  void refresh() {
    notifyListeners();
  }
}
